const express = require('express');
const multer = require('multer');
const path = require('path');

const app = express();

// 设置 multer 存储配置
const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, 'upload'); // 确保 'upload' 文件夹存在
    },
    filename: function (req, file, cb) {
        cb(null, Date.now() + path.extname(file.originalname)); // 使用时间戳作为文件名
    }
});

const upload = multer({ storage: storage });

// 处理文件上传请求
app.post('/upload', upload.single('installPackage'), (req, res) => {
    if (req.file) {
        res.status(200).send('文件上传成功');
    } else {
        res.status(400).send('文件上传失败');
    }
});

app.listen(3000, () => {
    console.log('服务器已启动，监听端口 3000');
}); 